﻿$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
 
Get-Content .\cookie.txt  | foreach {
#vr 6   .weibo.com  /
$line=$_ -split '/' | select -First 1
$tokens=$_.Split('  ',[System.StringSplitOptions]::RemoveEmptyEntries)
$c=@{
 name=$tokens[0]
 value=$tokens[1]
 domain=$tokens[2]
}
 $cookie = New-Object System.Net.Cookie
 $cookie.Name=$c.name
 $cookie.Value=$c.Value
 $cookie.Domain=$c.domain
 $session.Cookies.Add($cookie)
}
 
for($i=1;$i -le 214555;$i++){
$r=Invoke-RestMethod "http://weibo.com/aj/v6/comment/big?ajwvr=6&id=4009043251108698&page=$i&__rnd=1471928579930" -WebSession $session -UserAgent 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36'
$page = $i.ToString().PadLeft('7','0')
$r.data.html | Out-File "E:\weibo.data\$page.html"
Write-Host "正在下载 $page 页"
}



$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
 
Get-Content .\cookie.txt  | foreach {
#vr 6   .weibo.com  /
$line=$_ -split '/' | select -First 1
$tokens=$_.Split('  ',[System.StringSplitOptions]::RemoveEmptyEntries)
$c=@{
 name=$tokens[0]
 value=$tokens[1]
 domain=$tokens[2]
}
 $cookie = New-Object System.Net.Cookie
 $cookie.Name=$c.name
 $cookie.Value=$c.Value
 $cookie.Domain=$c.domain
 $session.Cookies.Add($cookie)
}
 
for($i=1;$i -le 214555;$i++){
$r=Invoke-RestMethod "http://weibo.com/aj/v6/comment/big?ajwvr=6&id=4009043251108698&page=$i&__rnd=1471928579930" -WebSession $session -UserAgent 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36'
$page = $i.ToString().PadLeft('7','0')
$r.data.html | Out-File "E:\weibo.data\$page.html"
Write-Host "正在下载 $page 页"
}




function Add-WeiboPost
{
param(
    $User,
    $Post
)
$body = @{
AuthKey='*************'
User=$User
Post=$Post}
Invoke-RestMethod http://mr.lonsoon.com/query.php -Method post -Body $body
}
 
 
workflow Push-Data
{
    param($Posts)
    foreach -parallel ($post in $posts)
    {
        $a=Add-WeiboPost -User $post.user -Post $post.text
        Write-Output $a
    }
}
 
$num=0;
ls E:\weibo.data | foreach {
    $posts = GetWeibo -file $_.FullName
    Push-Data -Posts $posts
    $_ | del
    $num += $posts.Count
    Write-Host "Upload $num posts"
}